/** 
 * https://leetcode.cn/problems/maximum-erasure-value/submissions/560558953/
 * 1695. 删除子数组的最大得分
 * medium,  2024.9.2
 * 滑动窗口
 */

class Solution {
public:
    int maximumUniqueSubarray(vector<int>& nums) {
        int n=nums.size();
        unordered_map<int, int> mp;
        int score=0, s=0;
        for(int l=0, r=0;r<n; r++){
            mp[nums[r]] ++;
            s+=nums[r];
            while(l<r && mp[nums[r]]>1){
                s-=nums[l];
                mp[nums[l]]--;
                l++;
            }
            score = max(s, score);
        }
        return score;
    }
};